package put.poznan.qmese.matlab.model;

public class Matrix implements Chunk {

	private String id;
	private double[][] matrix;
	private int n, m;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public double[][] getMatrix() {
		return matrix;
	}

	public void setMatrix(double[][] matrix) {
		this.matrix = matrix;
		this.m=matrix.length;
		this.n=matrix[0].length;
	}

	public void initialize(int n, int m) {
		this.n=n;
		this.m=m;
		matrix = new double[n][m];
	}

	public void clear(int n, int m) {
		matrix = new double[n][m];
	}

	public int getN() {
		return n;
	}

	public void setN(int n) {
		this.n = n;
	}

	public int getM() {
		return m;
	}

	public void setM(int m) {
		this.m = m;
	}

	
	public void set(int n,int m, double value){
//		if (getN()<n || getM()<m){
//			throw new IllegalArgumentException("Index out of bounds");
//		}
		matrix[n][m] = value;
	}

	public double get(int n, int m) {
		if (getN() < n || getM() < m) {
			throw new IllegalArgumentException("Index out of bounds");
		}
		return matrix[n][m];
	}

	@Override
	public String toString() {
		StringBuffer  output = new StringBuffer();
		for(int i=0; i<n;i++){
			for (int j=0; j<m;j++){
				output.append(matrix[i][j]+",");
			}
			output.append("\n");
		}
		
		return output.toString();
	}
}
